//
//  myViewController.m
//  iNews
//
//  Created by lanou3g on 14-12-15.
//  Copyright (c) 2014年 张在青. All rights reserved.
//

#import "myViewController.h"
#import "myview.h"
#import "myCollectionViewController.h"
#import "myLoadingViewController.h"

#import "arcticViewController.h"
#import "pictureViewController.h"



@interface myViewController ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>

{
    float _m;
}

@property(nonatomic,retain)myview *myv;

@property(nonatomic, retain)NSMutableArray *myArray;
@property(nonatomic, retain)NSMutableArray *picArr;

@end

@implementation myViewController

-(void)dealloc{

    [_myv release];
    [_myArray release];
    [_picArr release];
    
    
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
        //self.title = @"更多";
        
        
        self.myv = [[[myview alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease];
    }
    return self;
}

-(void)loadView{

    self.view = self.myv;
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    //计算缓存
    NSURLCache *cache = [NSURLCache sharedURLCache];
    NSUInteger t = [cache currentMemoryUsage];
    _m = t / 1024.0 / 1024.0;
   
    //存文字的数组
    NSArray *arr = [NSArray arrayWithObjects:@"我的收藏",@"我的下载", nil];
    NSArray *arr1 = [NSArray arrayWithObjects:@"清空缓存", nil];
    NSArray *arr2 = [NSArray arrayWithObjects:@"关于我们",@"检查更新", nil];
    
    //存图片的数组
    NSArray *arr3 = [NSArray arrayWithObjects:@"contenttoolbar_hd111_fav@2x.png",@"laodDown.png", nil];
  //  NSArray *arr4 = [NSArray arrayWithObjects:@"", nil];
    self.picArr = [NSMutableArray arrayWithObjects:arr3, nil];
    self.myArray = [NSMutableArray arrayWithObjects:arr, arr1,arr2, nil];
    
    self.myv.myTab.delegate = self;
    
    self.myv.myTab.dataSource = self;
    
    //注册cell
    
    [self.myv.myTab registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell_id"];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return self.myArray.count;

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  
    return [self.myArray[section] count];


}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell_id" forIndexPath:indexPath ];
   
    
    cell.imageView.image = [UIImage imageNamed:@""];
    
    
    cell.textLabel.text = self.myArray[indexPath.section][indexPath.row];
    return cell;
    
   

}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {
        
        if (indexPath.row == 0) {
            
            myCollectionViewController *collection = [[[myCollectionViewController alloc] init] autorelease];
            
            [self.navigationController pushViewController:collection animated:YES];
        }else if(indexPath.row == 1){
            myLoadingViewController *load = [[[myLoadingViewController alloc] init] autorelease];
            
            [self.navigationController pushViewController:load animated:YES];
        }
        
    }
    if (indexPath.section == 1) {
        
        if (indexPath.row == 0) {
            
            NSString *s = [NSString stringWithFormat:@"当前缓存(%.2lfM)",_m];
            UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:@"是否清除?" message:s delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil] ;
            
            [alertV show];

            [alertV release];
        }
    }
    
    if (indexPath.section == 2) {
        
        UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:@"感谢您的关注" message:@"暂无更多" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil] ;
        [alertV show];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [alertV dismissWithClickedButtonIndex:0 animated:YES];
            [alertV release];
        });
    }

}
//alertView代理方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        //清除缓存
        NSURLCache *cache = [NSURLCache sharedURLCache];
       
        [cache removeAllCachedResponses];
        
        _m = 0;
    }
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
